package com.globalwave.system.web;

import com.globalwave.base.BaseAction;
import com.globalwave.common.ArrayPageList;
import com.globalwave.system.entity.Organization;
import com.globalwave.system.entity.OrganizationCriterion;
import com.globalwave.system.service.OrganizationService;
import com.globalwave.system.web.annotations.Pid;
import com.opensymphony.xwork2.Preparable;

public class OrganizationAction extends BaseAction implements Preparable {

    private static final long serialVersionUID = 7244882365197775441L;
    
    private OrganizationService organizationService ;
    private Organization organization ;
    private Long user_id ;
    private OrganizationCriterion organizationCriterion ; 
    private Long[] privilege_ids ; 
    private Long[] organization_ids ;
    
    public String execute() throws Exception {        
        
        return this.list();        
        
    }
    

    @Pid(value=111)
    public String list() throws Exception {  
        
        ArrayPageList<Organization> pageList = 
            organizationService.query(organizationCriterion,pageIndex,pageSize,null) ;

        renderXML(pageList.asXML()) ;
        
        return null ;  
        
    }

    @Pid(value=112)
    public String create()  throws Exception {        
        
        
        Object newOrganization = organizationService.create(organization, privilege_ids) ;

        renderXML(this.getSuccessCreateMessage(newOrganization).asXML()) ;
        
        return null;    
        
    }

    @Pid(value=113)
    public String update()  throws Exception {     

        
        organizationService.update(organization, privilege_ids) ;

        renderXML(this.getSuccessUpdateMessage(organization).asXML()) ;
        
        return null;    
        
    }

    @Pid(value=114)
    public String delete()  throws Exception {

        if (this.organization_ids == null) { 
            organizationService.delete(organization) ;
        } else {
            organizationService.deleteAll(organization_ids) ;
        }
        
        renderXML(this.getSuccessDeleteMessage().asXML()) ;
        
        return null;    
        
    }

    @Pid(value=101)
    public String userBelongTo()  throws Exception {
        ArrayPageList<Organization> pageList = 
            organizationService.userBelongTo(user_id) ;

        renderXML(pageList.asXML()) ;        
        return null;    
        
    }
    
    public void prepare() throws Exception {
        // TODO Auto-generated method stub
        
    }
    
    public void setOrganizationService(OrganizationService organizationService) {
        this.organizationService = organizationService;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public OrganizationCriterion getOrganizationCriterion() {
        return organizationCriterion;
    }

    public void setOrganizationCriterion(OrganizationCriterion organizationCriterion) {
        this.organizationCriterion = organizationCriterion;
    }

    public Long getUser_id() {
        return user_id;
    }

    public void setUser_id(Long user_id) {
        this.user_id = user_id;
    }

    public Long[] getPrivilege_ids() {
        return privilege_ids;
    }

    public void setPrivilege_ids(Long[] privilege_ids) {
        this.privilege_ids = privilege_ids;
    }

    public void setOrganization_ids(Long[] organization_ids) {
        this.organization_ids = organization_ids;
    }


}
